using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class LaunchMenu : MonoBehaviour
{
	[SerializeField]
	private Text m_MusicText;

	[SerializeField]
	private Text m_SoundText;

	[SerializeField]
	private Image m_SoundOn;

	[SerializeField]
	private Image m_SoundOff;

	[SerializeField]
	private Image m_MusicOn;

	[SerializeField]
	private Image m_MusicOff;

	[SerializeField]
	private Animator m_Animator;

	[SerializeField]
	private bool m_Show;

	public void OnSettingButtonClick()
	{
		string trigger = (!m_Show) ? "Show" : "Hide";
		m_Animator.SetTrigger(trigger);
		m_Show = !m_Show;
	}

	public void OnMainButtonAdjust()
	{
		if (m_Show)
		{
			m_Show = false;
			m_Animator.SetTrigger("Hide");
		}
	}

	private void Start()
	{
		SetMusic();
		SetSound();
		m_Show = false;
	}

	private void SetMusic()
	{
		m_MusicOn.gameObject.SetActive(AudioManager.Music);
		m_MusicOff.gameObject.SetActive(!AudioManager.Music);
		AudioManager.SetMusic(AudioManager.Music);
	}

	private void SetSound()
	{
		m_SoundOn.gameObject.SetActive(AudioManager.Sound);
		m_SoundOff.gameObject.SetActive(!AudioManager.Sound);
		AudioManager.SetSound(AudioManager.Sound);
	}

	public void MusicButtonClick()
	{
		AudioManager.Music = !AudioManager.Music;
		SetMusic();
	}

	public void SoundButtonClick()
	{
		AudioManager.Sound = !AudioManager.Sound;
		SetSound();
	}

	private void Update()
	{
		GameObject currentSelectedGameObject = EventSystem.current.currentSelectedGameObject;
		if (currentSelectedGameObject != null && IsOnSettingBtn(currentSelectedGameObject.name))
		{
			return;
		}
		Touch[] touches = Input.touches;
		for (int i = 0; i < touches.Length; i++)
		{
			Touch touch = touches[i];
			int fingerId = touch.fingerId;
			if (EventSystem.current.IsPointerOverGameObject(fingerId))
			{
				GameObject currentSelectedGameObject2 = EventSystem.current.currentSelectedGameObject;
				if (currentSelectedGameObject2 != null && IsOnSettingBtn(currentSelectedGameObject2.name))
				{
					break;
				}
			}
			if (touch.phase == TouchPhase.Ended && m_Show)
			{
				OnSettingButtonClick();
			}
		}
	}

	private bool IsOnSettingBtn(string name)
	{
		if (name.Equals("MusicOn") || name.Equals("MusicOff") || name.Equals("SoundOn") || name.Equals("SoundOff") || name.Equals("SettingToggle"))
		{
			return true;
		}
		return false;
	}
}
